package com.my.study.designPatterns.compoundPattern;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Flock implements Quackable {

    private List<Quackable> quackables = new ArrayList<>();

    private Observerable observerable;

    public Flock() {

        observerable = new Observerable(this);
    }

    public void add(Quackable quackable){

        quackables.add(quackable);
    }


    @Override
    public void quack() {

        Iterator<Quackable> iterator = quackables.iterator();
        while (iterator.hasNext()){
            System.out.println("-----");
            iterator.next().quack();
        }
    }


    @Override
    public void registerObserver(DuckObserver observer) {

        observerable.registerObserver(observer);
    }

    @Override
    public void notifyObservers() {

        observerable.notifyObservers();
    }
}
